//Discussion:
//Weighted average of the boids vs the weighted centroid.
//Collision avoidance - dynamic force allocation through packeting.
//Same radius velocity matching and flock centering.
//Use min velocity as well to prevent stopping of boids.

import java.util.*; 

//Speed parameter for the simulation
float TIMESTEP = 0.2;

//Population numbers of the boids
int NUMBOIDS = 10;
int MAX_BOIDS = 100;
int MIN_BOIDS = 5;

//Screen size information
int WIDTH = 800;
int HEIGHT = 800;
float EPS = 0.1;

//Simulation parameter **** HANDLE WITH CARE :) ****
float CENTERING_RADIUS = 200;
float COLLISION_AVOID_RADIUS = 40;
float MATCH_RADIUS = 60;
int MAX_RANDOM_X = 2;
int MAX_RANDOM_Y = 2;

float MAX_ACCELERATION = 20.0;
float MAX_VELOCITY = 5.0;
float MIN_VELOCITY = 2.0;

int MAX_PREV_POSITIONS = 30; //How long a trail to show

BoidList g_boidList;

void setup()
{
  size(WIDTH, HEIGHT);
  g_boidList = new BoidList(); 
  PFont font = loadFont("arcena.vlw");
  textFont(font, 20);
}

void draw()
{
  background(0);
  g_boidList.update();
  g_boidList.draw();
}

void keyPressed()
{
  if (key == 's' || key == 'S')
  {
    g_boidList.reset();
  }
  else if (key == 'a' || key == 'A')
  {
    g_boidList.toggleAttract();
  }
  else if (key == 'r' || key == 'R')
  {
    g_boidList.toggleRepel();
  }
  else if (key == 'p' || key == 'P')
  {
    g_boidList.toggleLeaveTrail();
  }
  else if (key == 'c' || key == 'C')
  {
    g_boidList.clear(); 
  }
  else if (key == '1')
  {
    g_boidList.toggleCentering();
  }
  else if (key == '2')
  {
    g_boidList.toggleVelocityMatch();
  }
  else if (key == '3')
  {
    g_boidList.toggleCollision();
  }
  else if (key == '4')
  {
    g_boidList.toggleRandom();
  }
  else if (key =='+' || key == '=')
  {
    g_boidList.addBoid();
  }
  else if (key =='-' || key == '_')
  {
    g_boidList.removeBoid();
  }
  else if (key == ' ')
  {
    g_boidList.togglePause();
  }
}
